import { CacheModule } from '@nestjs/cache-manager';
import { Module } from '@nestjs/common';
import { redisStore } from 'cache-manager-redis-store';
import { RedisCacheService } from './redis-cache.service';

@Module({
    imports: [
        CacheModule.registerAsync({
            // @ts-ignore
            useFactory(...args) {
                return {
                    store: async () => await redisStore({
                        socket: {
                            host: process.env.redis_config_host,
                            port: Number(process.env.redis_config_port)
                        },
                        password: process.env.redis_config_pwd,
                    }),
                    // ttl: 60 * 60 * 3
                }
            },
        })
    ],
    providers: [RedisCacheService],
    exports: [RedisCacheService]
})
export class RedisCacheModule { }
